home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / hsrc_117.zip / LOADAREA.C < prev    next >
Text File  |  1990-11-12  |  3KB  |  128 lines

  1. #include "msgg.h"
  2. #include "twindow.h"
  3. #include "keys.h"
  4. #include "headedit.h"
  5.  
  6.  
  7. char * pascal next_one(char *,char);
  8.  
  9. void pascal load_areas (void) {
  10.  
  11.     register int x;
  12.     int fp;
  13.     struct ffblk f;
  14.     static char string[256];
  15.     word tempareas=0;
  16.     char *p,*pp;
  17.     word zone,net,node,point;
  18.  
  19.     if(!strchr(msgareas,'/') && !strchr(msgareas,'\\') && !strchr(msgareas,':')) sprintf(string,"%s%s",path,msgareas);
  20.     else strcpy(string,msgareas);
  21.     if(findfirst(string,&f,0)) strcpy(string,searchpath(msgareas));
  22.     if (findfirst(string,&f,0)) return;
  23.     if((fp=(_open(string,O_DENYNONE | O_TEXT | O_RDONLY)))==-1) {
  24.         error_message(" Can't open MSGAREAS.XBS ");
  25.         return;
  26.     }
  27.     while (!eof(fp)) {
  28.         if (!fgetsx(string,255,fp)) break;
  29.         if (*string=='\n' || *string==';') continue;
  30.         maxareas++;
  31.     }
  32.     lseek(fp,0L,SEEK_SET);
  33.     marea=(struct _marea far*)farmalloc((maxareas+1)*sizeof(struct _marea));
  34.     if (marea==NULL) {
  35.         error_message(" No memory for areas ");
  36.         maxareas=0;
  37.         _close(fp);
  38.         return;
  39.     }
  40.     for(x=0;x<maxareas;x++) marea[x].name=NULL;
  41.     while (!eof(fp) && tempareas<maxareas+1) {
  42.         if (!fgetsx(string,255,fp)) break;
  43.         if (*string=='\n' || *string==';') continue;
  44.         stripcr(string);
  45.         marea[tempareas].name=strdup(strtok(string,","));
  46.         marea[tempareas].attr=(word)atoi(strtok(0," ,"));
  47.         marea[tempareas].max=(word)atoi(strtok(0," ,"));
  48.         marea[tempareas].number=(word)atoi(strtok(0," ,"));
  49.         if(!marea[tempareas].name) {
  50.             sprintf(string," No memory for name of area %u",marea[tempareas].number);
  51.             error_message(string);
  52.             sleep(1);
  53.             for(x=0;x<tempareas;x++) {
  54.                 if(marea[x].name) free(marea[x].name);
  55.             }
  56.             maxareas=0;
  57.             _close(fp);
  58.             farfree((void far *)marea);
  59.             marea=NULL;
  60.             return;
  61.         }
  62.         marea[tempareas].thisaddr=0;    /* Defaults */
  63.         marea[tempareas].thisname=0;
  64.         p=strtok(0," ,");
  65.         p=strtok(0," ,");
  66.         pp=strtok(0,"\n");
  67.         if(!pp) goto AllForThatOne;
  68.         for(x=0;x<5;x++) {
  69.             p=NULL;
  70.             if(*pp!=',') {
  71.                 p=pp;
  72.                 while(*pp!=',' && *pp!=0) pp++;
  73.                 if(*pp!=0){
  74.                     *pp=0;
  75.                     pp++;
  76.                 }
  77.             }
  78.             else pp++;
  79.         }
  80.         if(p) {
  81.             zone=(word)atol(p);
  82.             p=next_one(p,':');
  83.             net=(word)atol(p);
  84.             p=next_one(p,'/');
  85.             node=(word)atol(p);
  86.             p=next_one(p,'.');
  87.             point=(word)atol(p);
  88.             for(x=0;x<(word)noaddress;x++) {
  89.                 if(zone==address[x]->zone && net==address[x]->net && node==address[x]->node && point==address[x]->point) {
  90.                     marea[tempareas].thisaddr=(x+1);
  91.                     break;
  92.                 }
  93.             }
  94.         }
  95.         p=NULL;
  96.         if(*pp!=',') {
  97.             p=pp;
  98.             while(*pp!=',' && *pp!=0) pp++;
  99.             if(*pp!=0){
  100.                 *pp=0;
  101.                 pp++;
  102.             }
  103.         }
  104.         else pp++;
  105.         if(p) {
  106.             for(x=0;x<(word)noalias;x++) {
  107.                 if(!stricmp(alias[x],p)) {
  108.                     marea[tempareas].thisname=(x+1);
  109.                     break;
  110.                 }
  111.             }
  112.         }
  113. AllForThatOne:
  114.         if (marea[tempareas].number>higharea) higharea=marea[tempareas].number;
  115.         tempareas++;
  116.     }
  117.     if (tempareas<maxareas) maxareas=tempareas;
  118.     _close(fp);
  119. }
  120.  
  121.  
  122. char * pascal next_one (char *p,char delim) {
  123.  
  124.     while(*p && *p!=delim) p++;
  125.     if(*p)p++;
  126.     return p;
  127. }
  128.